package com.hyst.web;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;

import com.hyst.domain.FreeAudition;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.Student;
import com.hyst.domain.Trylistenmanage;
import com.hyst.domain.TrylistenmanageView;
import com.hyst.service.TrylistenmanageService;

/**
 * @Description:controller
 * @author�?dy 
 *@Date�?2018��09��20��
 */
@RestController
@RequestMapping("trylistenmanages")
@CrossOrigin(maxAge = 3600, origins = "*")
public class TrylistenmanageController {
	@Autowired
	private TrylistenmanageService trylistenmanageService;

	private String student;
	
	@GetMapping
	public ResultPage<TrylistenmanageView> getProjects(TrylistenmanageView trylistenmanage) {
		return ResultPage.success(trylistenmanageService.list(trylistenmanage));
	}

	// 2018-10-13 chenbin: 下拉框条件查询
	@GetMapping("selectByCondition/{selectCondition}")
	public ResultPage<TrylistenmanageView> selectByCondition(final TrylistenmanageView trylistenmanage, @PathVariable("selectCondition") final String selectCondition) {
		return ResultPage.success(trylistenmanageService.selectByCondition(trylistenmanage, selectCondition));
	}


	@GetMapping("getFuzeren/{studentid}")
	public ResultBean getFuzerenByStudentId(@PathVariable("studentid") String studentid) {
		return trylistenmanageService.getFuzerenId(studentid);
	}


	@PostMapping
	public ResultBean<Trylistenmanage> creat(final Trylistenmanage trylistenmanage) {
		return ResultBean.success(trylistenmanageService.insert(trylistenmanage));
	}

	@PostMapping("update")
	public ResultBean<Trylistenmanage> updateInfo(final Trylistenmanage trylistenmanage) {
		trylistenmanage.setIsdeleted(1);
		return ResultBean.success(trylistenmanageService.update(trylistenmanage));
	}


	/**
	 * @Description: 根据主键查询
	 * @param id
	 * @return ResultBean<Trylistenmanage>
	 */
	@GetMapping("{id}")
	public ResultBean<Trylistenmanage> getByPriKey(@PathVariable("id") final Integer id) {
		return ResultBean.success(trylistenmanageService.getByPriKey(id));
	}

	/**
	 * @Description: 根据主键更新全字�?
	 * @param trylistenmanage
	 * @return ResultBean<Trylistenmanage>
	 */
	@PatchMapping("{id}")
	public ResultBean<Trylistenmanage> update(final Trylistenmanage trylistenmanage) {
		return ResultBean.success(trylistenmanageService.update(trylistenmanage));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param trylistenmanage
	 * @return ResultBean<Trylistenmanage>
	 */
	//@PutMapping("{id}")
	@PostMapping("id")
	public ResultBean<Trylistenmanage> updatePatch(@PathVariable("id") final Integer id,
			final Trylistenmanage trylistenmanage) {
		return ResultBean.success(trylistenmanageService.updateSelective(trylistenmanage));
	}

	/**
	 * @Description: 根据主键删除
	 * @param id
	 * @return ResultBean<Trylistenmanage>
	 */
	@DeleteMapping("{id}")
	public ResultBean<Trylistenmanage> delete(@PathVariable("id") final Integer id) {
		return ResultBean.success(trylistenmanageService.delete(id));
	}


//	@GetMapping("saveRemark/{uniqueId}")
//	public ResultBean<Trylistenmanage> saveRemark(@PathVariable("uniqueId") final String uniqueId) {
//		
//		String uniqueIdtest = null;
//		try {
//			uniqueIdtest =new String(uniqueId.getBytes("ISO-8859-1"), "utf8");//解决中文格式乱码
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}		
//		System.out.println(uniqueIdtest);
//		return ResultBean.success(trylistenmanageService.saveRemark(uniqueIdtest));
//	}
	
	
	@PostMapping("saveRemark")
	public ResultBean<Trylistenmanage> saveRemark(@RequestParam(value = "postMsg") String uniqueId) {
		
//		String uniqueIdtest = null;
//		try {
//			uniqueIdtest =new String(uniqueId.getBytes("ISO-8859-1"), "utf8");//解决中文格式乱码
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}		
		System.out.println(uniqueId);
		return ResultBean.success(trylistenmanageService.saveRemark(uniqueId));
	}
	
	
	@GetMapping("savestateEdit1")
	public ResultBean<Trylistenmanage> savestateEdit1(@RequestParam("postMsg") final String uniqueId) {
		String uniqueIdtest = null;
		try {
			uniqueIdtest =URLDecoder.decode(uniqueId,"utf-8");//解决中文格式乱码
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(uniqueIdtest);
		return ResultBean.success(trylistenmanageService.savestateEdit(uniqueIdtest));
	}

	
	@PostMapping("savestateEdit")
	public ResultBean<Trylistenmanage> savestateEdit(@RequestParam(value = "postMsg") String postMsg) {		
//		String uniqueIdtest = null;
//		try {
//			uniqueIdtest =new String(uniqueId.getBytes("ISO-8859-1"), "utf8");//解决中文格式乱码
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}		
		System.out.println(postMsg);
		return ResultBean.success(trylistenmanageService.savestateEdit(postMsg));
	}
	
	
	
	@GetMapping("savedoDelete/{uniqueId}")
	public ResultBean<Trylistenmanage> savedoDelete(@PathVariable("uniqueId") final String uniqueId) {			
		System.out.println(uniqueId);
		return ResultBean.success(trylistenmanageService.savedoDelete(uniqueId));
	}

	
	@GetMapping("getByUid/{uniqueId}")
	public ResultBean<TrylistenmanageView> getByUid(@PathVariable("uniqueId") final String uniqueId) {
		return ResultBean.success(trylistenmanageService.getByUid(uniqueId));
	}
	
	
	@GetMapping("getByConditon/{searchConditon}")
	public ResultPage<TrylistenmanageView> getByConditon(TrylistenmanageView trylistenmanage,@PathVariable("searchConditon") final String searchConditon) {
		String conditiontest = null;
		try {
			 conditiontest =new String(searchConditon.getBytes("ISO-8859-1"), "utf8");//解决中文格式乱码
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(conditiontest);
		return ResultPage.success(trylistenmanageService.getByConditon(trylistenmanage,conditiontest));
	}


	@GetMapping("getReport")
	public ResultBean getReport(@RequestParam("id") Integer id){
		return ResultBean.success(trylistenmanageService.getReportData(id));
	}
}
